home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / FILER / X-FILES.ZIP / 057 / !X-Files / c / debug < prev    next >
Text File  |  1996-03-25  |  2KB  |  88 lines

  1. /* debug.c */
  2.  
  3. #include "debug.h"
  4. #include "kernel.h"
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <stdarg.h>
  8.  
  9. #ifndef Tracker_Open
  10. #define Tracker_Open   0xCF000
  11. #define Tracker_Close  0xCF001
  12. #define Tracker_SetPos 0xCF002
  13. #define Tracker_WriteS 0xCF003
  14. #define Tracker_CLS    0xCF004
  15. #define Tracker_Simple 0xCF005
  16. #endif
  17.  
  18. int SavedSP;
  19. static int __trackHandle = 0;
  20.  
  21. static int __open(char *title, int width, int height, int flags)
  22. {
  23.    _kernel_swi_regs regs;
  24.    _kernel_oserror *err;
  25.  
  26.    regs.r[0] = (int) title;
  27.    regs.r[1] = width;
  28.    regs.r[2] = height;
  29.    regs.r[3] = flags;
  30.  
  31.    if (err = _kernel_swi(Tracker_Open, ®s, ®s), err)
  32.       return -1;
  33.  
  34.    return regs.r[0];
  35. }
  36.  
  37. static void __close(int handle)
  38. {
  39.    _kernel_swi_regs regs;
  40.  
  41.    regs.r[0] = handle;
  42.    (void) _kernel_swi(Tracker_Close, ®s, ®s);
  43. }
  44.  
  45. static void __writes(int handle, const char *s)
  46. {
  47.    _kernel_swi_regs regs;
  48.  
  49.    regs.r[0] = handle;
  50.    regs.r[1] = (int) s;
  51.    
  52.    (void) _kernel_swi(Tracker_WriteS, ®s, ®s);
  53. }
  54.  
  55. static void __exithandler(void)
  56. {  if (__trackHandle)
  57.       __close(__trackHandle);
  58. }
  59.  
  60. static void __outs(const char *s)
  61. {
  62.    if (__trackHandle == 0)
  63.    {  if (__trackHandle = __open("X-Files", 80, 5000, 1), __trackHandle > 0)
  64.          atexit(__exithandler);
  65.       else
  66.          return;
  67.    }
  68.    else if (__trackHandle < 0)
  69.       return;
  70.       
  71.    __writes(__trackHandle, s);
  72. }
  73.  
  74. /* External interface */
  75.  
  76. void TRACE(const char *fmt, ...)
  77. {
  78.    va_list ap;
  79.    char buf[300];
  80.  
  81.    va_start(ap, fmt);
  82.    vsprintf(buf, fmt, ap);
  83.    va_end(ap);
  84.  
  85.    __outs(buf);
  86. }
  87.  
  88.